﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using log4net;
using FSS.BLL.Entities;
namespace FSS.BLL.Services
{
	#region ProductService

	/// <summary>
	/// ProductService object for Ibatis mapped table 'Product'.
	/// </summary>
	public class ProductService : IProductService
	{
		private static readonly ILog log = LogManager.GetLogger(typeof(ProductService).Name);
	  	private static volatile ProductService _ProductService = null;
        public static ProductService GetInstance()
        {
            if (_ProductService == null)
            {
                lock (typeof(ProductService))
                {
                    if (_ProductService == null) // double-check
                        _ProductService = new ProductService();
                }
            }
            return _ProductService;
        }
		public ProductService()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        /// <summary>
        /// Tự động thêm mới or cập nhật lại phiếu nhập
        /// </summary>
        /// <param name="obj">VoucherInEntity Đối tượng</param>
        /// <returns>Mã của phiếu nhập</returns>
        public Int64 InsertUpdate(ProductEntity obj)
        {
            ProductEntity resul = ExecuteQueryForObject<ProductEntity>("ProductInsert", obj);
            return resul.ProductId;

        }
        /// <summary>
        /// Tim kiem Mặt hàng
        /// </summary>
        /// <returns></returns>
        public IList<ProductEntity> SearchProduct(string KeySer, int Start, int Limit, out int Total)
        {Total=0;
            try
            {
                ProductEntity obj = new ProductEntity
                {
                    ProductName = KeySer,
                    Start = Start,
                    EndNum = Limit,
                    TotalRow = Total
                };
                IList<ProductEntity> resul = ExecuteQueryForList<ProductEntity>("ProductSearchAvg", obj);
                Total = obj.TotalRow;
                return resul;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                return null;
            }
        }
        public int ProductUpdateCheck(ProductEntity objE)
        {
            try
            {
                ExecuteUpdate("ProductUpdateCheck", objE);
                return 1;
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
                return 0;
            }
        }
	}
	#endregion  
}
